package com.io.file;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * 编写一个测试文件一般属性的程序。
 * （如显示文件的路径、绝对路径、显示文件是否可写、
 * 显示文件是否可读、显示文件的大小等属性）
 *
 * @author: Jovi
 * @createTime: 2017-06-20 13:51
 **/
public class FileInfo {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter file name：");
        StringBuffer buf = new StringBuffer();
        char ch;
        try {
            while ((ch = (char) System.in.read()) != '\n') {
                buf.append(ch);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        File file = new File(buf.toString().trim());
        if (file.exists()) {
            if (file.isFile()) {
                System.out.println("file name is：" + file.getName().substring(0, file.getName().lastIndexOf(".")));
                System.out.println("file path is：" + file.getPath());
                System.out.println("file absolute path is：" + file.getAbsolutePath());
                System.out.println("file can read：" + file.canRead());
                System.out.println("file can writer：" + file.canWrite());
                System.out.println("file lenght：" + file.length() + "B");
            } else {
                System.out.println("It is not a file！");
            }
        } else {
            System.out.println("It can't find the file");
        }
    }
}
